#include "Term.h"

using namespace std;

template <typename T>
Term<T>::Term()
{
    throw Unsupported_template_exception();
}

Term<int>::Term()
{
}

string Term<int>::toString(vector<int> vals)
{
    if (vals.size() != powers.size())
    {
        cout << "vals.length: " << vals.size() << endl;
        return toString();
    }
        
    ostringstream output;
    output << coefficient;
    
    for (int i = (powers.size() - 1); i >= 0; --i)
        output << '(' << vals[i] << ')' << '^' << powers[i];
    
    return output.str();
}

Term<int>::Term(int myCoefficient, vector<double> myPowers)
{
    coefficient = myCoefficient;
    powers = myPowers;
}

double Term<int>::evaluate(vector<int> variables)
{
    double total = 1;
    for (unsigned int i = 0; i < powers.size(); ++i)
        total *= pow(double(variables[i]), powers[i]);
    
    total *= coefficient;
    
    return total;
}

/** 
 * It converts the term to a readable string. Here's a detailed description.
 */
template <typename T>
string Term<T>::toString()
{
    ostringstream output;
    output << coefficient;
    
    for (int i = (powers.size() - 1); i >= 0; --i)
        output << char(i + 'a') << '^' << powers[i];
    
    return output.str();
}


template <typename T>
T Term<T>::getCoefficient()
{
    return coefficient;
}

template <typename T>
vector<double> Term<T>::getPowers()
{
    return powers;
}

template class Term<int>;
